#ifndef DISPLAYWIDGET_H
#define DISPLAYWIDGET_H

#include <QGLWidget>
#include <QTimer>
#include <QStringList>

#include "Face.h"
#include "Mask.h"

namespace Ui {
    class DisplayWidget;
}

class DisplayWidget : public QGLWidget
{
    Q_OBJECT

public:
    explicit DisplayWidget(QWidget *parent = 0);
    ~DisplayWidget();

public slots:
    void newImage(QImage image);
    void setRects(QVector<QRect> rects);
    void setFaces(QVector<Face> faces);

protected:
    void initializeGL();
    void paintGL();
    void resizeGL(int w, int h);

private slots:
    void switchMasks();

private:
    void createNewFrameTexture();
    void drawFrameTexture(int index = 0);
    void replaceFrameTexture(QImage& frame, int index = 0);
    QRect adjustForDisplay(QRect rect);
    QLine adjustForDisplay(QLine line);
    QPoint adjustForDisplay(QPoint point);
    void drawRects();
    void drawFaces();
    void drawLine(QLine line, QColor color = Qt::white, float width = 1.0f);
    void drawRect(QRect rect, QColor color = Qt::white, float width = 1.0f);
    void drawEllipse(QPoint center, float rx, float ry, float angle, QColor color = Qt::white, float width = 1.0f);

    Ui::DisplayWidget *ui;
    QImage currentImage;
    QVector<GLuint> frameTextures;
    QVector<QRect> currentRects;
    QVector<Face> currentFaces;
    QVector<Face> previousFaces;
    QImage rectImage;
    Mask* mask;
    QVector<Mask*> masks;
    QTimer maskTimer;
};

#endif // DISPLAYWIDGET_H
